import Hammer from 'Hammer';

let KnockoutHammerBinding = {
    register: function(Knockout) {
        Knockout.bindingHandlers.swipeLeft = {
            init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
                let f = Knockout.unwrap(valueAccessor());
                new Hammer(element).on('swipeleft', function(e) {
                    let viewModel = bindingContext.$data;
                    f.apply(viewModel, arguments);
                });
            },
        };

        Knockout.bindingHandlers.swipeRight = {
            init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
                let f = Knockout.unwrap(valueAccessor());
                new Hammer(element).on('swiperight', function(e) {
                    let viewModel = bindingContext.$data;
                    f.apply(viewModel, arguments);
                });
            },
        };
    },
};

export default KnockoutHammerBinding;
